package com.longdaji.decoration.ui.login;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jaeger.library.StatusBarUtil;
import com.longdaji.decoration.Constants;
import com.longdaji.decoration.DecorationApplication;
import com.longdaji.decoration.R;
import com.longdaji.decoration.base.BaseActivity;
import com.longdaji.decoration.ui.login.passwordLogin.PasswordLoginActivity;
import com.longdaji.decoration.ui.main.MainActivity;
import com.longdaji.decoration.ui.register.RegisterActivity;
import com.longdaji.decoration.utils.ScreenUtils;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by longtao on 2017/12/19.
 */

public class LoginActivity extends BaseActivity implements LoginContract.View {

    private static final String TAG = LoginActivity.class.getSimpleName();
    @Inject
    LoginPresenter mPresenter;

    @BindView(R.id.iv_background)
    ImageView ivBackground;
    @BindView(R.id.tv_look)
    TextView tvLook;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "LoginActivity onCreate 3");
        setContentView(R.layout.activity_login);
        setUnBinder(ButterKnife.bind(this));
        if (mPresenter != null)
            mPresenter.setView(this);

        initView();
    }

    private void initView() {
        DecorationApplication.addDetroyActivity(this);
        StatusBarUtil.setTranslucentForImageView(this, 0, null);
        ScreenUtils.changeLight(ivBackground, -50);
    }

    @Override
    protected void onDestroy() {
        if (mPresenter != null)
            mPresenter.detachView();
        super.onDestroy();
    }

    @OnClick({R.id.btn_login, R.id.btn_register, R.id.tv_look})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_login:
                startActivity(new Intent(this, PasswordLoginActivity.class));
                break;
            case R.id.btn_register:
                startActivity(new Intent(this, RegisterActivity.class));
                break;
            case R.id.tv_look:
                Intent intent = new Intent();
                intent.putExtra(Constants.EXTRA_LOOK, true);
                DecorationApplication.setJustLook(true);
                MainActivity.start(this, intent);
                finish();
                break;
            default:
                break;
        }
    }


    @Override
    public void openMain() {
        startActivity(MainActivity.getStartIntent(this));
        //startActivity(LocationActivity.getStartIntent(this));
    }

}
